//package com.j.lemon.learn.onlytest;
//
//import com.j.lemon.learn.thread.threadPool.ThreadPoolCase1;
//import org.apache.commons.collections4.ListUtils;
//import org.springframework.data.domain.PageRequest;
//import org.springframework.data.domain.Pageable;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.concurrent.*;
//
///**
// * @Author lijunjun
// * @Date 2019-05-27 17:37
// * @Description
// */
//public class Test2 {
//    //创建一个线程池
//    private static final ExecutorService executorService = new ThreadPoolExecutor(50, 100, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>(), r -> new Thread(r, "user-sign"));
//
//    public void signUser3() throws Exception {
//
//        // 获得签名数据类型最新版本的签名项对象
//        PmiSignConfigEntity pmiSignConfigEntity = pmiConfigService.findLastestVerConfByType(ApiServiceType.API_USER);
//
//        //签名项目未配置
//        if (null == pmiSignConfigEntity) {
//            logger.info("-------------------签名项未配置！------------");
//            return;
//        }
//        Criteria criteria = Criteria.where("removed").is(false);
//        Query query = Query.query(criteria);
////        Pageable pageable = new PageRequest(0, 500000);
//        List<UserEntity> userLists;
//        logger.info("-------------------开始用户签名------------");
//
//        long time = System.currentTimeMillis();
////            query.with(pageable);
//        userLists = mongo.find(query, UserEntity.class, "userEntity");
//        logger.info("------------查询用户用时：" + (System.currentTimeMillis() - time));
//
//        List<List<UserEntity>> userGroups = new ArrayList<>();
//
//        //把130W数据分配到100个数组当中,每个数组13000个
//        List<UserEntity> temp = new ArrayList<>();
//        for (int i = 0; i < userLists.size(); i++) {
//            temp.add(userLists.get(i));
//            if (temp.size() == 13000) {
//                userGroups.add(temp);
//                temp = new ArrayList<>();
//            }
//        }
//
//        List<Callable<Integer>> tasks = new ArrayList<>();
//
//        //使用线程池用100个线程处理100个数组，每个线程处理13000个用户
//        for (List<UserEntity> userGroup : userGroups){
//            tasks.add(() -> {
//                for (UserEntity user : userGroup) {
//                    //为每个用户进行签名
//                    sign(user,pmiSignConfigEntity);
//                }
//                logger.debug(userGroup.size()+"个用户已完成签名");
//                return userGroup.size();
//            });
//        }
//
//        //该方法，所有任务执行完成后才会返回
//        executorService.invokeAll(tasks);
//        executorService.shutdown();
//
//        logger.debug("任务结束");
//
//        //对list进行分片，然后并行处理
////        int dataSize = userLists.size();
////        boolean special = dataSize % MaxSize == 0;
////        List<List<UserEntity>> users = ListUtils.partition(userLists, MaxSize);
////
////        int threadNum = users.size();
////
//        ExecutorService exec = Executors.newFixedThreadPool(users.size());
////
////        List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
////
////        Callable<Integer> task = null;
////
////        List<String> cutList = null;
////
////        for (int i = 0; i < threadNum; i++) {
////
////            if (i == threadNum - 1) {
////
////                if (special) {
////
////                    break;
////
////                }
////            }
////            final int l = i;
////
////            task = new Callable<Integer>() {
////
////                @Override
////                public Integer call() throws Exception {
////                    users.get(l).stream().forEach(s -> {
////                        sign(s, pmiSignConfigEntity);
////                    });
////                    return 1;
////
////                }
////
////            };
////            tasks.add(task);
////        }
////        List<Future<Integer>> results = null;
////        results = exec.invokeAll(tasks);
////
////        for (Future<Integer> future : results) {
////            logger.info("线程返回值          " + future.get());
////
////        }
////        // 关闭线程池
////        exec.shutdown();
////        System.out.println("------------线程任务执行结束-------------------");
////        userLists.clear();
////        pageable = new PageRequest(pageable.getPageNumber() + 1, pageable.getPageSize());
//    }
//
//
//}
